/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entity;

import java.io.Serializable;
import java.math.BigInteger;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author WinKiQue58
 */
@Entity
@Table(name = "PRODUCT_TYPE")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "ProductType.findAll", query = "SELECT p FROM ProductType p"),
    @NamedQuery(name = "ProductType.findByIdProductType", query = "SELECT p FROM ProductType p WHERE p.productTypePK.idProductType = :idProductType"),
    @NamedQuery(name = "ProductType.findByIdEnterprise", query = "SELECT p FROM ProductType p WHERE p.productTypePK.idEnterprise = :idEnterprise"),
    @NamedQuery(name = "ProductType.findByName", query = "SELECT p FROM ProductType p WHERE p.name = :name")})
public class ProductType implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected ProductTypePK productTypePK;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 180)
    @Column(name = "NAME")
    private String name;
    @JoinColumn(name = "ID_ENTERPRISE", referencedColumnName = "ID_ENTERPRISE", insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Enterprise enterprise;

    public ProductType() {
    }

    public ProductType(ProductTypePK productTypePK) {
        this.productTypePK = productTypePK;
    }

    public ProductType(ProductTypePK productTypePK, String name) {
        this.productTypePK = productTypePK;
        this.name = name;
    }

    public ProductType(BigInteger idProductType, BigInteger idEnterprise) {
        this.productTypePK = new ProductTypePK(idProductType, idEnterprise);
    }

    public ProductTypePK getProductTypePK() {
        return productTypePK;
    }

    public void setProductTypePK(ProductTypePK productTypePK) {
        this.productTypePK = productTypePK;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Enterprise getEnterprise() {
        return enterprise;
    }

    public void setEnterprise(Enterprise enterprise) {
        this.enterprise = enterprise;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (productTypePK != null ? productTypePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ProductType)) {
            return false;
        }
        ProductType other = (ProductType) object;
        if ((this.productTypePK == null && other.productTypePK != null) || (this.productTypePK != null && !this.productTypePK.equals(other.productTypePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entity.ProductType[ productTypePK=" + productTypePK + " ]";
    }
    
}
